#!/bin/bash
#
# Wrapper script for launching the Flexible Update Notification System, if it
# is enabled. Funs will be launched as a background task.
#
# Author:   Dr. Mike Murphy (mmurphy2@coastal.edu)
# Revision: 12 January 2013
#
#   Copyright 2011-2013 Coastal Carolina University
#   Copyright 2007-2008 Clemson University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#

function show_help() {
   cat << EOF
Usage: start-funs

Starts the Pulley Flexible Update Notification System, which provides a
tray icon (FreeDesktop/X11) to notify the user when updates are available.
EOF
}


function show_summary() {
   echo "Starts the Flexible Update Notification System"
}

ARGS=$(getopt -o "k:" -l "help,shorthelp" \
              -n "$0" -- "$@")
if [ $? -ne 0 ]; then
   exit 2
fi

eval set -- "$ARGS"

while [ ! "$1" = "--" ]; do
   case "$1" in
      --help)
         shift
         show_help
         exit 0
      ;;
      --shorthelp)
         shift
         show_summary
         exit 0
      ;;
   esac
done

shift


if [ $# -ne 0 ]; then
   echo "Command usage: pulley start-funs" >&2
   exit 2
fi

chk=$("${PULLEY_COMMAND_DIR}/get-context" pulley_funs_enabled)

if [ "${chk}" = "true" ]; then
   cd "${PULLEY_PACKAGE_DIR}/pulley"
   python2 funs.py 100 "${PULLEY_RESOURCE_DIR}/Updates_Icon2.png" \
      "${PULLEY_RESOURCE_DIR}/Updating_Icon2.png" &
fi
